<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>数据表格</title>
		<link rel="stylesheet" href="../../component/pear/css/pear.css" />
	</head>
	<body class="pear-container">

		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">

						<div class="layui-inline">
							<label class="layui-form-label">教师ID</label>
							<div class="layui-input-inline">
								<input type="text" name="teaId" placeholder="教师ID" autocomplete="off" class="layui-input">
							</div>
						</div>
		 

						<div class="layui-inline">
							<div class="layui-input-inline">
								<button class="layui-btn" lay-submit="" lay-filter="user-query">
									<i class="layui-icon">&#xe615;</i>
								</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>

		<div class="layui-card">
			<div class="layui-card-body">
				<table id="user-table" lay-filter="user-table"></table>
			</div>
		</div>

	<script type="text/html" id="user-bar">
	 	<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="comment">查询评论</button>
	</script>

 
 
	<script type="text/html" id="user-type">
		{{#if (d.subjectType == 1) { }}
		<span>语文</span>
		{{# }else if(d.subjectType == 2){ }}
		<span>英语</span>
		{{# }else if(d.subjectType == 3){ }}
		<span>数学</span>
		{{# }else if(d.subjectType == 4){ }}
		<span>物理</span>
		{{# }else if(d.subjectType == 5){ }}
		<span>化学</span>
		{{# }else if(d.subjectType == 6){ }}
		<span>生物</span>
		{{# }else if(d.subjectType == 7){ }}
		<span>历史</span>
		{{# }else if(d.subjectType == 8){ }}
		<span>政治</span>
		{{# }else if(d.subjectType == 9){ }}
		<span>地理</span>
		{{# } }}
	</script>


	<script type="text/html" id="order-type">
		{{#if (d.status == 1) { }}
		<span>待确认</span>
		{{# }else if(d.status == 2){ }}
		<span>已接单</span>
		{{# }else if(d.status == 3){ }}
		<span>已结束</span>
		{{# }else if(d.status == 4){ }}
		<span>已取消</span>
		{{# }else if(d.status == 5){ }}
		<span>已拒绝</span>
		{{# } }}
	</script>
	
	<script type="text/html" id="user-createTime">
		{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}
	</script>

		<script src="../../component/layui/layui.js"></script>
		<script src="../../component/pear/pear.js"></script>
		<script src="../../api/baseApi.js"></script>
		<script src="../../api/subjectApi.js"></script>
		<script src="../../api/orderApi.js"></script>
		<script src="../../component/js/core.util.js"></script>
	
		
		<script>
			layui.use(['table', 'form', 'jquery', 'drawer', 'dropdown','laydate'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let drawer = layui.drawer;
				let dropdown = layui.dropdown;
				let laydate = layui.laydate;

				laydate.render({
					elem: '#date1',
					type: 'datetime'
				});
		
				let cols = [
					[{
							type: 'checkbox'
						},
						{
							title: '编号',
							field: 'id',
							align: 'center',
							width: 100
						},
						{
							title: '课程标题',
							field: 'subjectTitle',
							align: 'center'
						},
						{
							title: '上课时间',
							field: 'time',
							align: 'center'
						},
						{
							title: '上课地点',
							field: 'address',
							align: 'center',
							width: 80
						},
						{
							title: '课程类型',
							field: 'subjectType',
							align: 'center',
							templet: '#user-type'
						},
						{
							title: '创建时间',
							field: 'createTime',
							align: 'center',
							templet: '#user-createTime'
						},
						{
							title: '操作',
							toolbar: '#user-bar',
							align: 'left',
							width: 160,
							fixed: 'right'
						}
					]
				]
				
				table.render({
					request: {
						pageName: 'pageNum' , //页码的参数名称，默认：page
						limitName: 'pageSize' //每页数据量的参数名，默认：limit
					},
					elem: '#user-table',
					url: '',
					contentType: 'application/json',
					method: 'POST',
					page: true,
					cols: cols,
					skin: 'line',
					limits: [10, 20, 30, 40],
					limit: 10,
					toolbar: '#user-toolbar',
					defaultToolbar: [{
						layEvent: 'refresh',
						icon: 'layui-icon-refresh',
					}, 'filter', 'print', 'exports'],
					parseData: function(res) { //res 即为原始返回的数据
						return {
							"code": res.code, //解析接口状态
							"msg": res.message, //解析提示文本
							"count": res.data.total, //解析数据长度
							"data": res.data.records //解析数据列表
						};
					},
				});

				table.on('tool(user-table)', function(obj) {
					if (obj.event === 'over') {
						window.over(obj.data);
					} else if (obj.event === 'cancel') {
						window.cancel(obj.data);
					} else if (obj.event === 'comment') {
						window.comment(obj.data);
					} 
				});
 

				form.on('submit(user-query)', function(data) {
					data.field.status = 3
					table.reload('user-table', {
						where: data.field,
						'url': orderListUrl
					})
					return false;
				});

				form.on('switch(user-enable)', function(obj) {
					layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
				});

				window.comment = function(data) {
					console.info(data);
					const status = data.status
					console.info("当前要评论的订单: ", JSON.stringify(data))
					if(status === 3){
						
						 var index = layer.open({
							 title: '订单评价',
							 type: 2,
							 shade: 0.2,
							 maxmin:true,
							 shadeClose: true,
							 area: ['100%', '100%'],
							 content: "comment.html?orderId="+data.id,
							success: function (layero,index) {
								
								var body = layer.getChildFrame('body', index);
								body.find("[name='orderId']").val(data.id);
								
							},
							 end: function () {
								 // 刷新当前页
								 window.location.reload()
							 }
						 });
 
					}else{
						layer.msg("此课程不能被评论", {
							icon: 1,
							time: 1000
						}, function() {
							 
						});
					}
				}
				
				window.refresh = function(param) {
					table.reload('user-table');
				}
			})
            
		</script>
	</body>
</html>
